<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>内容列表</title>
<import type='css' file="css.main" />
<load href="__PUBLIC__/js/jquery-1.9.1.min.js" />
<import type='js' file="js.main" />
</head>

<body>
<style type="text/css">
.seoption{padding-top:10px; text-align:center;}
.seoption select{border:solid 1px #ccc; border-radius:3px; height:30px; line-height:24px; border-right:none;}
button.okglian{display:block; clear:both; width:70px; margin:0px auto; margin-top:6px; background:none; background-color:#ff5454; color:#fff; border:none; border-radius:5px; line-height:22px; cursor:pointer;}
b.extena{color: #ff5454; font-weight: normal; font-size: 12px; margin-left: 3px;}
</style>
<!-- 预览窗口开始 -->
<div class="previewbg" style="display:none;">
	<input style="margin-top:92px; width:375px;"></input>
	<iframe id="previewwidnow" src="" frameborder="0" scrolling="auto" style="margin-top:0px;"></iframe>
</div>
<div class="jiumabg">
	<div class="jiuma" style="width:250px; height:90px; margin-top:200px;">
    	<div class="jiumaclose" style="background-color:#333;">X</div>
		<div class="jiuma_from"><input name='searkey' type="text" placeholder="按某个码的名称搜索" /><a id="searchsubmit">搜索</a></div>
		<div class="jiumalist seoption">
			<input type="hidden" name="preid" class="preid" />
            <span class="fl cnt">
                <select name="typeid" class="template form-control" style="width:140px;">
                    <volist name='wymaselect' id='v'>
                    <option value="{$v.id}">{$v.typename}</option>
                    </volist>
                </select>
                <select name="menuid" class="template form-control" style="margin-left:-4px; border-left:none; border-right:solid 1px #ccc; width:110px;"></select>
            </span>
            <button class="okglian">确定关联</button>
                        
        </div>
	</div>
</div>
<!-- 预览窗口结束 -->
<div class="main-frame">
	<div class="position">华人码 > 内容列表</div>
	<div class="table-list">
	 <table width="100%" border="1" cellspacing="0" cellpadding="0" class="indextable">
		    <tr class="th-bg">
		      <th width="4%">序号</th>
		      <th width="30%">内容标题</th>
		      <th width="22%">类目</th>
		      <th width="6%">优先级</th>
		      <th width="9%">创建时间</th>
		      <th width="8%">发布人</th>
		      <th width="6%">浏览量</th>
              <th width="6%">状态</th>
		      <th width="10%" style="text-align:right;">操作</th>
	        </tr>
	        <volist name='articlelist' id='v' empty="$empty">
		    <tr class="tr-line">
		      <td>{$v.id}</td>
		      <td class="guanlian"><a class='preview' path='{:U('Home/Article/index',array('id'=>$v['id']))}'>{$v.title} {:W('Menutype/getexten',array('img' => $v['thumbimg'], 'str' => $v['extendattr']))}</a><span v="{$v.id}">关联</span></td>
		      <td class="mbxue">{:W('Menutype/typename',array($v['typeid']))} > {:W('Menutype/nowhere',array($v['menuid']))}</td>
		      <td>{$v.weight}</td>
		      <td style="font-size:12px;">{$v.pubdate}</td>
		      <td>{$v.issuer}</td>
		      <td>{$v.pv}</td>
              <td>
				  <a <if condition="$Thinkphp.session.userinfo.type eq 1">onclick="changestate('{:U('Type/changestate',array('id'=>$v['id'],'state'=>$v['state'],'table'=>'article'))}')"</if>>
					  <if condition="$v['state'] eq 1">
						  <span class="topen" title="开启"></span>
						  <else />
						  <span style="color: #ff5454;">审核中</span>
					  </if>
				  </a>
			  </td>
		      <td style='text-align:right;'>
		      	<a class='preview' path='{:U('Home/Article/index',array('id'=>$v['id']))}'>预览</a> /
				<a href="{:U('Index/articleedit',array('id'=>$v['id']))}">编辑</a> /
				<a class="resdel" refurl="{:U('Type/delete',array('id'=>$v['id'],'table'=>'article'))}">删除</a>
			  </td>
	        </tr>
	        </volist>
      </table>
    </div>
    <if condition="$page neq 1">
	    <if condition="$Think.get.id neq ''">
	    	<div class="page pages"><a href="{:U('articleadd',array('id'=>I('get.id'),'rootid'=>I('get.rootid'),'add'=>'true'))}">添加 </a>{$page}</div>
	    <else />
	    	<div class="page">{$page}</div>
	    </if>
    </if>
</div>
<script type="text/javascript">
	$(function(){
		$("a.resdel").each(function(index, element) {
			var t = $(this);
			t.click(function(){
				var r=confirm("想好！确定要删除吗？");
				if (r==true){
					var refurl = $(this).attr('refurl');
					location.href = refurl;
				}else{
					return false;
				}
			})
		});
	})
</script>
<script type="text/javascript">
$(function(){
	
	$("#searchsubmit").click(function(){
		var key = $("input[name='searkey']").val();
		if($.trim(key)!=""){
			$.post("{:U('Index/gettypedata')}", {key:key,random:Math.random()}, function(data){
			   if(data!=0){
				   $("select[name='typeid']").html(data);
				   var wymaselect = $("select[name='typeid']");
				   if(wymaselect.val()!=""){
					   showsubmenu(wymaselect.val());
					   $("select[name='typeid']").css({"border-right":"none"});
					   $("select[name='menuid']").show(); 
					   $("button.okglian").show();
				   }else{
					   $("select[name='typeid']").css({"border-right":"solid 1px #ccc"});
					   $("select[name='menuid']").hide();
					   $("button.okglian").hide();    
				   }
			   }
			})
		}
	})
	
	$("button.okglian").click(function(){
		var typeid = $("select[name='typeid']").val();
		var menuid = $("select[name='menuid']").val();
		if(menuid>0 && typeid>0){
			var preid = $(".preid").val();
			if(preid!=0 || preid!=""){
				$.get("{:U('Index/cpdata')}", {preid:preid,typeid:typeid,menuid:menuid,random:Math.random()}, function(data){
					if(data==1){
						alert('关联成功！');
						location.href='/Admin/Index/articlelist';
					}
				})
			}
		}
	})

	function getTypestr(strpath){
		$.get(strpath, function(result){
			$("select[name='menuid']").html(result);
		});
	}
	var wymaselect = $("select[name='typeid']");
	function showsubmenu(val){
		var typeID = val;
		if(typeID>0){
			getTypestr("/Admin/Index/articleadd/rootid/"+typeID);
		}	
	}
	showsubmenu(wymaselect.val());
	wymaselect.change(function(){
		var v = $(this).val();
		showsubmenu(v);
	})

	$(".guanlian").each(function(index, element) {
        var t = $(this);
		t.find("span").click(function(){
			var getarticleID = $(this).attr("v");
			$(".jiumabg").fadeIn();
			$(".jiumabg .jiuma").show();
			$("input[name='preid']").val(getarticleID);
		})
    });	
	$(".jiumaclose").click(function(){
		$(".preid").val(null);
		$(".jiumabg .jiuma").hide();
		$(".jiumabg").fadeOut();
	})
})
</script>
</body>
</html>
